<template>
  <div>
    姓名
    <el-input v-model="student.name" style="width: 120px"></el-input>
    <br>
    性别
    <el-select v-model="student.sexId">
      <el-option v-for="sex in sexList" :key="sex.id" :value="sex.id" :label="sex.str"></el-option>
    </el-select>
    <br>
    创建时间
    <el-input v-model="student.created" type="date" style="width: 120px"></el-input>
    <br>
    班级
    <el-select v-model="student.classId">
      <el-option v-for="cla in claList" :key="cla.id" :value="cla.id" :label="cla.str"></el-option>
    </el-select>
    <br>
    <el-button @click="add">添加</el-button>
  </div>
</template>

<script>
export default {
  name: 'AddView',
  data () {
    return {
      student: {
        name: '',
        sexId: null,
        classId: null,
        created: ''
      },
      sexList: [],
      claList: []
    }
  },
  methods: {
    add () {
      this.axios.post('/stu/add', this.student)
        .then(res => {
          if (res.data.code === 200) {
            this.$message.success('ok')
            this.$router.push('/student')
          } else {
            this.$message.error('no')
          }
        })
    },
    claclick () {
      this.axios.get('/select/list2')
        .then(res => {
          this.claList = res.data
        })
    },
    sexclick () {
      this.axios.get('/select/list')
        .then(res => {
          this.sexList = res.data
        })
    }
  },
  created () {
    this.sexclick()
    this.claclick()
  }
}
</script>

<style scoped>

</style>
